package br.com.ldml2;

import br.com.ldml.Tripla;
import br.com.util.Escritor;
import br.com.util.TripleSet;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

@XStreamAlias("similar")
public class Similar implements LdmlCommand {
	private static final String similiarProperty = "http://www.w3.org/2002/07/owl#sameAs";
	
	@XStreamAsAttribute
	String dataset1, individual1, individual2, output;
	
	public String getInput1() {
		return dataset1;
	}

	public void setInput1(String input1) {
		this.dataset1 = input1;
	}

	public String getIndividual1() {
		return individual1;
	}

	public void setIndividual1(String individual1) {
		this.individual1 = individual1;
	}

	public String getIndividual2() {
		return individual2;
	}

	public void setIndividual2(String individual2) {
		this.individual2 = individual2;
	}

	@Override
	public void exec(String tmpFileName) {
		TripleSet ts1 = new TripleSet(dataset1);
				
		Tripla tr1 = new Tripla(individual1, similiarProperty, individual2);
		Tripla tr2 = new Tripla(individual2, similiarProperty, individual1);
		
		ts1.addTriple(tr1);
		ts1.addTriple(tr2);
		
		XStream xs2 = new XStream();
		Escritor e = new Escritor();
		e.abreArquivo(tmpFileName, true);
		e.gravaArquivo(new String[] { xs2.toXML(ts1) } );
		
		e.fechaArquivo();
	}

	@Override
	public String getOutput() {
		return output;
	}

	@Override
	public void setOutput(String output) {
		this.output = output;
	}
}
